#define _CRT_SECURE_NO_WARNINGS
#include<vector>
#include<unordered_map>
using namespace std;
int numberOfArithmeticSlices(vector<int>& nums) {
    int n = nums.size();
    vector<vector<int>> dp(n, vector<int>(n, 0));
    unordered_map<long long, vector<int>> hash;
    hash[nums[0]].push_back(0);

    int sum = 0;
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            long long x = (long long)2 * nums[i] - nums[j];
            if (hash.count(x)) {
                for (auto& index : hash[x]) {
                    dp[i][j] += dp[index][i] + 1;
                }
            }
            sum += dp[i][j];
        }
        hash[nums[i]].push_back(i);
    }
    return sum;
}